Imports DTO
Imports System.Data.OleDb
Public Class LichHocDAO
    Inherits AbstractDAO
    Public Function LayBang() As DataTable
        Dim dt As New DataTable()
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim strSQL As String
        strSQL = "select * from LichLopHoc"
        Dim da As OleDbDataAdapter
        da = New OleDbDataAdapter(strSQL, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function
    Public Sub CapNhatBang(ByVal dt As DataTable)
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim strSQL As String
        strSQL = "Select * from LichLopHoc"
        Dim da As OleDbDataAdapter
        da = New OleDbDataAdapter(strSQL, cn)
        Dim cb As New OleDbCommandBuilder(da)
        da.Update(dt)
        cn.Close()
    End Sub
    Public Function LayDanhSach() As IList
        Dim ds As New ArrayList()
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim strSQL As String
        strSQL = "Select * from LichLopHoc"
        Dim cmd As New OleDbCommand(strSQL, cn)
        Dim dr As OleDbDataReader
        dr = cmd.ExecuteReader()
        While (dr.Read())
            Dim lhDTO As New LichHocDTO
            lhDTO.MaLichLopHoc = dr("MaLichLopHoc")
            lhDTO.MaPhanCong = dr("MaPhanCong")
            lhDTO.SoTietHoc = dr("SoTietHoc")
            lhDTO.Thu = dr("Thu")
            lhDTO.TietHocBatDau = dr("TietHocBatDau")
            ds.Add(lhDTO)
        End While
        dr.Close()
        cn.Close()
        Return ds
    End Function
    Public Function TiemKiemTheoMa(ByVal maphancong As String) As LichHocDTO
        Dim lhDTO As New LichHocDTO
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim strSQL As String
        strSQL = "Select * from PhanCong Where MaPhanCong = " & maphancong
        Dim cmd As New OleDbCommand(strSQL, cn)
        Dim dr As OleDbDataReader
        dr = cmd.ExecuteReader()
        While (dr.Read())
            lhDTO.MaLichLopHoc = dr("MaLichLopHoc")
            lhDTO.MaPhanCong = dr("MaPhanCong")
            lhDTO.SoTietHoc = dr("SoTietHoc")
            lhDTO.Thu = dr("Thu")
            lhDTO.TietHocBatDau = dr("TietHocBatDau")

        End While
        dr.Close()
        cn.Close()
        Return lhDTO
    End Function
    Public Sub Them(ByVal lhDTO As LichHocDTO)
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim strSQL As String
        strSQL = "Insert into LichHoc(MaLichLopHoc, MaPhanCong, SoTietHoc, Thu, TietHocBatDau) value= " & _
        " ( '" & lhDTO.MaLichLopHoc & "', '" & lhDTO.MaPhanCong & "', '" & lhDTO.SoTietHoc & "', '" & lhDTO.Thu & "', " & _
        lhDTO.TietHocBatDau & ")"
        Dim cmd As New OleDbCommand(strSQL, cn)
        cmd.ExecuteNonQuery()
        strSQL = "Select @@INDENTITY"
        cmd = New OleDbCommand(strSQL, cn)
        lhDTO.MaPhanCong = cmd.ExecuteScalar()
        cn.Close()
    End Sub
    Public Sub XoaTheoMa(ByVal maphancong As String)
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim strSQL As String
        strSQL = "Delete from PhanCong Where MaPhanCong= " & maphancong
        Dim cmd As New OleDbCommand(strSQL, cn)
        cmd.ExecuteNonQuery()
        cn.Close()

    End Sub
End Class
